package com.ruoyi.framework.config;

import com.codahale.metrics.MetricRegistry;
import com.ruoyi.framework.killbill.EventBusRegister;
import org.killbill.bus.DefaultPersistentBus;
import org.killbill.bus.api.PersistentBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.util.Properties;

@Configuration
public class KillBillConfig {

    private static final Logger log = LoggerFactory.getLogger(KillBillConfig.class);

    @Bean
    public MetricRegistry buildMetricRegistry(){
        return new MetricRegistry();
    }

    @Bean(initMethod = "start")
    public PersistentBus initBus(@Autowired DataSource dataSource, @Autowired @Qualifier("queueConfig") Properties queueConfig,@Autowired MetricRegistry metricRegistry){
        DefaultPersistentBus defaultPersistentBus = new DefaultPersistentBus(dataSource,queueConfig,metricRegistry);
        return defaultPersistentBus;
    }
}
